

    const mysql = require('mysql')
    const DBconfig = require('../config/db-config.js')

    let pool = mysql.createPool(DBconfig.tpadmin)

    let allSqlAction = (sql, value) => {
        return new Promise(
            (resolve, reject) => {
                pool.getConnection(
                    function(err, connection) {
                        if(err) {
                            console.log(err)
                            reject(err)
                        }
                        else {
                            console.log("数据库连接成功")
                            connection.query(sql, value, (err, row) => {
                                if(err) reject(err)
                                else resolve(row)
                                connection.release()
                            })
                        }
                    }
                )
            }
        )
    }

    module.exports = {
        allSqlAction
    }